﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.Presenter.Reports;
using MS.InformationManagement.Support;

namespace MS.InformationManagement.WP.DocumentCenter.CostReport
{
    public partial class CostReportUserControl : BaseControl, ICostReportView
    {
        #region [Private Fields]

        private CostReportPresenter _Presenter; 
        
        #endregion

        #region [Event Handlers]

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            _Presenter = new CostReportPresenter(this);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                _Presenter.LoadReportData();                
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            string isDlg = Request.QueryString.Get("IsDlg");
            if (!string.IsNullOrEmpty(isDlg) && isDlg.Equals("1")) { this.CloseWindow(); }
            else { this.GoCurrentUserHome(); }
        }
 
        #endregion

        #region [ICostReportView Members]

        public DateTime StartDate
        {
            get
            {
                return dtInicio.SelectedDate;
            }
            set
            {
                dtInicio.SelectedDate = value;
            }
        }

        public DateTime EndDate
        {
            get
            {
                return dtFin.SelectedDate;
            }
            set
            {
                dtFin.SelectedDate = value;
            }
        }

        public System.Collections.Generic.List<DAL.DTOs.PieChartDTO> ReportValues
        {
            get
            {
                return spgrdCostReport.DataSource as System.Collections.Generic.List<DAL.DTOs.PieChartDTO>;
            }
            set
            {
                spgrdCostReport.DataSource = value;
                spgrdCostReport.DataBind();
            }
        }

        #endregion
    }
}